package com.zephyr.vchcenter.bpm.decision;

import org.apache.log4j.Logger;

import com.hiaward.bpm.context.ServiceContext;
import com.hiaward.bpm.exception.ParameterException;
import com.hiaward.bpm.exception.RuleException;
import com.hiaward.bpm.exception.ServiceException;
import com.hiaward.bpm.rule.Decision;
import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.helper.SpringHelper;

public class TallyManageDecisionHandler extends Decision{
	
	private static Logger log = Logger.getLogger(TallyManageDecisionHandler.class);
	@Override
	public void exceptionHandle(ServiceContext arg0) {
		
	}

	@Override
	public String make(ServiceContext sc) throws RuleException,
			ServiceException, ParameterException {
		log.debug("进入TallyManageDecisionHandler-----------------");
		String vchsid=(String)sc.getInputParameterValue("vchsid");
		IBaseDao dao=(IBaseDao)SpringHelper.getBean("baseDao");
        Voucher voucher=(Voucher)dao.findById("Voucher", vchsid);
        log.debug(vchsid+"..............................");
		String amount=voucher.getAmount();
		log.debug("���金额------------"+amount);
//		sc.setOutputParameterValue("accno", accno);
//		sc.setOutputParameterValue("vchno", vchno);
//		sc.setOutputParameterValue("amount", amount);
		if (amount.length()<6) {
			voucher.setRestally("1");
			dao.saveOrUpdate(voucher);
			log.debug("记账成功----------------------");
			return "to end";
		} else{
			voucher.setRestally("2");
			dao.saveOrUpdate(voucher);
			log.debug("转向记账失败审票--------------------");
			return "to tallyFailedAudit"; 
		}
	}
	
}
